import { IPanelTabPageControllerParams } from '@/core/interface';
import { PanelDetailController } from './panel-detail-controller';

/**
 * 面板分页面板控制器
 *
 * @export
 * @class PanelTabPageController
 * @extends {PanelDetailModel}
 */
export class PanelTabPageController extends PanelDetailController {
	/**
	 * 子项
	 *
	 * @type {string[]}
	 * @memberof PanelTabPageController
	 */
	public details: string[] = [];

	/**
	 * Creates an instance of PanelTabPageController.
	 * PanelTabPageController 实例
	 *
	 * @param {*} [IPanelTabPageControllerParams]
	 * @memberof PanelTabPageController
	 */
	constructor(opts: IPanelTabPageControllerParams) {
		super(opts);
		this.details = opts.details;
	}

	/**
	 * 加载数据
	 *
	 * @param {*} context
	 * @param {*} viewParams
	 * @memberof PanelTabPageController
	 */
	public async load(context: any, viewParams: any) {
		if (!this.parentName) {
			if (this.type == 'VIEWLAYOUT') {
				this.data = {};
			} else {
				this.data = this.panel.store.data;
			}
		} else {
			let parentItem =
				this.panel.store.layoutModelDetails[`${this.parentName}_${this.index}`];
			if (!parentItem) {
				parentItem = this.panel.store.layoutModelDetails[this.parentName];
			}
			if (parentItem) {
				if (
					parentItem.dataRegionType === 'MULTIDATA' &&
					parentItem['data'] &&
					parentItem['data'].length > 0
				) {
					this.data = parentItem.getData()[this.getIndex()];
				} else {
					this.data = parentItem.getData();
				}
			}
		}
	}
}
